import { reactive } from 'vue';
import { cascaderPowerStoreObjType, choosedItemType, cascaderPowerStoreRootPropsObjType } from './types';
const cascaderPowerStoreObj: cascaderPowerStoreObjType = {
  choosedData: new Map(),
  chooseItem(item: choosedItemType) {
    const { key } = item;
    if (this.choosedData.has(key)) {
      this.choosedData.delete(key);
      this.watchSign = !this.watchSign;
    } else {
      this.choosedData.set(key, item);
      this.watchSign = !this.watchSign;
    }
  },
  clearAllItem() {
    this.choosedData.clear();
    this.watchSign = !this.watchSign;
  },
  getChoosedDataArr() {
    return [...this.choosedData.values()];
  },
  initChooseItem(arr) {
    this.choosedData.clear();
    arr.forEach(i => {
      this.chooseItem(i);
    });
    this.watchSign = !this.watchSign;
  },
  watchSign: false,
};
export const cascaderPowerStore = reactive(cascaderPowerStoreObj);

const cascaderPowerStoreRootPropsObj: cascaderPowerStoreRootPropsObjType = {
  props: {},
  setProps(val: any) {
    this.props = val;
  },
};
export const cascaderPowerStoreRootProps = reactive(cascaderPowerStoreRootPropsObj);
